package bit_operation;


public class BitOperation {
    /**
     * 位运算，或，与，非，异或
     * 1 | 0 = 1
     * 1 | 1 = 1
     * 0 | 1 = 1
     * 0 | 0 = 0
     * 1 & 0 = 0
     * 1 & 1 = 1
     * 0 & 1 = 0
     * 0 & 0 = 0
     * ~1 = -2
     * ~0 = -1
     * 1 ^ 0 = 1
     * 1 ^ 1 = 0
     * 0 ^ 1 = 1
     * 0 ^ 0 = 0
     * 1 ^ 2 ^ 3 = 0
     * 1 ^ (2 ^ 3) = 0
     * 1^2 =3
     * 2^1 =3
     * 异或：一种好记的方式，无进位相加
     * 
     * @param args
     */
    public static void main(String[] args) {
        // System.out.println("1 | 0 = " + (1 | 0));
        // System.out.println("1 | 1 = " + (1 | 1));
        // System.out.println("0 | 1 = " + (0 | 1));
        // System.out.println("0 | 0 = " + (0 | 0));
        // System.out.println("1 & 0 = " + (1 & 0));
        // System.out.println("1 & 1 = " + (1 & 1));
        // System.out.println("0 & 1 = " + (0 & 1));
        // System.out.println("0 & 0 = " + (0 & 0));
        // System.out.println("~1 = " + (~(0x01)));
        // System.out.println("~0 = " + (~(0x00)));

        // System.out.println("1 ^ 0 = " + (1 ^ 0));
        // System.out.println("1 ^ 1 = " + (1 ^ 1));
        // System.out.println("0 ^ 1 = " + (0 ^ 1));
        // System.out.println("0 ^ 0 = " + (0 ^ 0));

        // System.out.println("1 ^ 2 ^ 3 = " + (1 ^ 2 ^ 3));
        // System.out.println("1 ^ (2 ^ 3) = " + (1 ^ (2 ^ 3)));
        // System.out.println("1^2 =" + (1 ^ 2));
        // System.out.println("2^1 =" + (2 ^ 1));

        // // 不使用临时变量的前提下交换两个数的值start
        // int a = 10;
        // int b = 2;
        // System.out.println("a=" + a);
        // System.out.println("b=" + b);

        // a = a ^ b;
        // b = a ^ b;
        // a = a ^ b;
        // System.out.println("a=" + a);
        // System.out.println("b=" + b);
        // 不使用临时变量的前提下交换两个数的值 end


    }

    
}
